#!/bin/bash

set -e

if [ "$EUID" -ne 0 ]; then
    echo "This script must be run as root or with sudo."
    exit 1
fi

SERVICE_NAME="plugin_loader.service"

IS_ENABLED=$(systemctl is-enabled $SERVICE_NAME || true)

IS_ACTIVE=$(systemctl is-active $SERVICE_NAME || true)

if [ "$IS_ENABLED" == "enabled" ] && [ "$IS_ACTIVE" != "active" ]; then
    systemctl restart $SERVICE_NAME
fi

sleep 5